<template>
	<view class="box">
		<view class="statusBar" :style="{height:statusHeight}"></view>
		<view class="my">
			<view class="touxiang"><image :src="this.$store.state.userHeadImg"></image></view>
			<view class="name">{{userAccount}}</view>
		</view>
		<view class="contain">
			<view class="list" @click="myMsg">
				我的信息
			</view>
			<view class="list" @click="orderMsg">
				订单信息
			</view>
			<view class="list" @click="login">
				登录
			</view>
			<view class="list" @click="out">
				退出
			</view>
		</view>
	</view>
</template>

<script>
	export default{
		data(){
			return{
				// userAccount:'请登录',
				userHeadImg:'../../static/tabs/car.png',
				statusHeight:0,	
			}
		},
		onLoad(){
			// 获取设备信息 状态栏高度
			var info = uni.getSystemInfoSync();
			// console.log(info);
			this.statusHeight=info.statusBarHeight+'px';
			// console.log('加载');
			uni.removeStorageSync('token')
			// uni.removeStorageSync('userState')
		},
		methods:{
			login(){
				uni.navigateTo({
					url: '/pages/login/login'
				});
			},
			out(){
				var datas = {
					userAccount:'',
					userHeadImg:'',
					userPhone:''
				};
				this.$store.commit('LOGIN',datas);
			},
			orderMsg(){
				uni.navigateTo({
					url: '/pages/orderMsg/orderMsg'
				});
			},
			myMsg(){
				uni.request({
					url:"http://124.221.202.161/user/current",
					method:"GET",
					// 传什么过去 token??
					// data:this.$store.state.token,
					// data:uni.getStorageSync('token'),
					data: {
					        text: 'uni.request'
					},
					header: {
					        Authorization:uni.getStorageSync('token') //自定义请求头信息
					    },
					success(res) {
						console.log(res);
						// console.log("token为"+res.data.data.token);
						console.log("存储Storage的token"+uni.getStorageSync('token'));
						// console.log(uni.getStorageSync('userState'));
						if(!uni.getStorageSync('token')){
							console.log(0);
							// 提示用户
							return uni.showToast({
								title:'请先登录',
								icon:"error"
							})
						}else{
							console.log(1);
							uni.navigateTo({
								url: '/pages/myMsg/myMsg'
							});
						}
						
					}
				})
			}
		},
		computed:{
			userAccount:function(){
				return this.$store.state.userAccount;
			}
		}
	}
</script>

<style lang="scss">
	.box{
		position: relative;
		.statusBar{
			width: 100%;
			background-color: #fff;
		}
		.my{
			width: 100%;
			height: 550rpx;
			background:url(../../static/img/bg.webp);
			display: flex;
			justify-content: start;
			align-items: center;
			.touxiang{
				width: 130rpx;
				height: 130rpx;
				border-radius: 130rpx;
				background-color: black;
				margin:0 30rpx 0 80rpx;
				image{
					width:100%;
					height:100%;
					background-size: cover;
				}
			}
			.name{
				width:100rpx;
				height:50rpx;
				
			}
		}
		.contain{
				width: 100%;
				height: 400rpx;
				background-color:#eee;
				border-radius: 100rpx;
				position: absolute;
				top:400rpx;
				margin:100rpx auto;
				.list{
					width:100%;
					height: 100rpx;
					margin:0 0 0 100rpx;
					line-height: 100rpx;
					color:black;
				}	
			}
		
	}
	</style>